#pragma strict
var numTotal : int; //will hold total target fruit
var minTotal : int; //holds min total target fruit
var maxTotal : int; //hold max total target fruit

var numApples : int;
var numBlackberries : int;
var numBlueberries : int;
var numLemons : int;
var numPeaches : int;
var numStrawberries : int;

var numOne : int;
var numTwo : int;
var numThree : int;

var fruitOne : int;
var fruitTwo : int;
var fruitThree : int;

var targetApples : GameObject;
var targetBlackberries : GameObject;
var targetBlueberries : GameObject;
var targetLemons : GameObject;
var targetPeaches : GameObject;
var targetStrawberries : GameObject;

var targetAppleTotal : GameObject;
var targetBlackberryTotal : GameObject;
var targetBlueberryTotal : GameObject;
var targetLemonTotal : GameObject;
var targetPeachTotal : GameObject;
var targetStrawberryTotal : GameObject;



private var targetAppleScript : TargetApples;
private var targetBlackberryScript : TargetBlackberries;
private var targetBlueberryScript : TargetBlueberries;
private var targetLemonScript : TargetLemons;
private var targetPeachScript : TargetPeaches;
private var targetStrawberryScript : TargetStrawberries;

private var targetAppleTotalScript : TargetApples;
private var targetBlackberryTotalScript : TargetBlackberries;
private var targetBlueberryTotalScript : TargetBlueberries;
private var targetLemonTotalScript : TargetLemons;
private var targetPeachTotalScript : TargetPeaches;
private var targetStrawberryTotalScript : TargetStrawberries;


function Start () {
	
	targetAppleScript = targetApples.gameObject.GetComponent("TargetApples");
	targetBlackberryScript = targetBlackberries.gameObject.GetComponent("TargetBlackberries");
	targetBlueberryScript = targetBlueberries.gameObject.GetComponent("TargetBlueberries");
	targetLemonScript = targetLemons.gameObject.GetComponent("TargetLemons");
	targetPeachScript = targetPeaches.gameObject.GetComponent("TargetPeaches");
	targetStrawberryScript = targetStrawberries.gameObject.GetComponent("TargetStrawberries");
	
	targetAppleTotalScript = targetAppleTotal.gameObject.GetComponent("TargetApples");
	targetBlackberryTotalScript = targetBlackberryTotal.gameObject.GetComponent("TargetBlackberries");
	targetBlueberryTotalScript = targetBlueberryTotal.gameObject.GetComponent("TargetBlueberries");
	targetLemonTotalScript = targetLemonTotal.gameObject.GetComponent("TargetLemons");
	targetPeachTotalScript = targetPeachTotal.gameObject.GetComponent("TargetPeaches");
	targetStrawberryTotalScript = targetStrawberryTotal.gameObject.GetComponent("TargetStrawberries");
	
	
	CreatePie();
	

}

function Update () {

	// if (Input.GetKeyUp ("space")){
    //    CreatePie();
    // }
}

function CreatePie () {
	
	if (StaticVars.difficulty == 1){
		minTotal = 5;
		maxTotal = 10;
	}
	else if (StaticVars.difficulty == 2){
		minTotal = 10;
		maxTotal = 25;
	}
	else if (StaticVars.difficulty == 3){
		minTotal = 20;
		maxTotal = 50;
	}
	else {
	//do nothing
	}
	
	numApples = 0;
	numBlackberries = 0;
	numBlueberries = 0;
	numLemons = 0;
	numPeaches = 0;
	numStrawberries = 0;
	
	numTotal = Random.Range(minTotal, maxTotal+1);
	
	numOne = Random.Range(1, numTotal-1);
	numTwo = Random.Range(1, numTotal-numOne-1);
	numThree = numTotal - numOne - numTwo;
	
	fruitOne = Random.Range(1,7);
	
	for (var i = 1; i == 1; i = i){
		fruitTwo = Random.Range (1,7);
		if (fruitTwo != fruitOne){
			i = 0;
		}
	}
	
	for (var j = 1; j == 1; j = j){
		fruitThree = Random.Range (1,7);
		if (fruitThree != fruitTwo){
			if (fruitThree != fruitOne) {
				j = 0;
				}
			}
		}
	
	//Debug.Log("total: " + total);	
	Debug.Log("fruitOne: " + fruitOne);
	Debug.Log("fruitTwo: " + fruitTwo);
	Debug.Log("fruitThree: " + fruitThree);
	
	
	if (fruitOne == 1) {
		numApples = numOne;
		}
	else if (fruitOne == 2) {
		numBlackberries = numOne;
		}
	else if (fruitOne == 3) {
		numBlueberries = numOne;
		}
	else if (fruitOne == 4) {
		numLemons = numOne;
		}
	else if (fruitOne == 5) {
		numPeaches = numOne;
		}
	else if (fruitOne == 6) {
		numStrawberries = numOne;
		}
	else {
		//nothing
		}
		
	if (fruitTwo == 1) {
		numApples = numTwo;
		}
	else if (fruitTwo == 2) {
		numBlackberries = numTwo;
		}
	else if (fruitTwo == 3) {
		numBlueberries = numTwo;
		}
	else if (fruitTwo == 4) {
		numLemons = numTwo;
		}
	else if (fruitTwo == 5) {
		numPeaches = numTwo;
		}
	else if (fruitTwo == 6) {
		numStrawberries = numTwo;
		}
	else {
		//nothing
		}	
		
	if (fruitThree == 1) {
		numApples = numThree;
		}
	else if (fruitThree == 2) {
		numBlackberries = numThree;
		}
	else if (fruitThree == 3) {
		numBlueberries = numThree;
		}
	else if (fruitThree == 4) {
		numLemons = numThree;
		}
	else if (fruitThree == 5) {
		numPeaches = numThree;
		}
	else if (fruitThree == 6) {
		numStrawberries = numThree;
		}
	else {
		//nothing
		}	
		
		
	targetAppleScript.UpdateApples();
	targetAppleTotalScript.UpdateApples();
	targetBlackberryScript.UpdateBlackberries();
	targetBlackberryTotalScript.UpdateBlackberries();
	targetBlueberryScript.UpdateBlueberries();
	targetBlueberryTotalScript.UpdateBlueberries();
	targetLemonScript.UpdateLemons();
	targetLemonTotalScript.UpdateLemons();
	targetPeachScript.UpdatePeaches();
	targetPeachTotalScript.UpdatePeaches();
	targetStrawberryScript.UpdateStrawberries();
	targetStrawberryTotalScript.UpdateStrawberries();
	
	
	
	

}